package com.ucsd.cse135.db;

import java.sql.Connection;
import java.sql.DriverManager;

public class Database {
	
	/** Parameters to establish database connection **/
	
	private static final String HOST = "localhost";	
	private static final String DB   = "graduate_admission_system";
	private static final String USER = "gas";
	private static final String PW   = "cse135";
	private static final String PORT = "5432";
	
	static Connection conn;
	
	/** Method to open database connection **/
	
	public static Connection open(){
		
		try {
			Class.forName("org.postgresql.Driver");
			conn = DriverManager.getConnection("jdbc:postgresql://" + HOST + ":" + PORT + "/" + DB, USER, PW);
			
			return conn;
		}
		catch (Exception e) {
			e.printStackTrace();
			return null;
		}
		
	}
	
	/** Method to close database connection **/
	
	public static void close() {
		
		try {
			conn.close();
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
		
	}
}
